home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 194_01 / concat0.c < prev    next >
Text File  |  1985-11-13  |  1KB  |  62 lines

  1. /* [CONCAT0.C of JUGPDS Vol.17]
  2. *****************************************************************
  3. *                                *
  4. *    Written by  Hakuo Katayose (JUG-CP/M No.179)        *
  5. *            49-114 Kawauchi-Sanjuunin-machi        *
  6. *            Sendai, Miyagi 980                          *
  7. *            Phone: 0222-61-3219                *
  8. *                                *
  9. *    Edited & tested by Y. Monma (JUG-C/M Disk Editor)       * 
  10. *                                *
  11. *****************************************************************
  12. */
  13.  
  14. /* concat - concatenate named files onto standard output */
  15.  
  16. #include "stdio.h"
  17. #include <dio.h>
  18.  
  19. main(argc, argv)
  20. int    argc;
  21. char     **argv;
  22.  
  23. {
  24.     struct _buf inbuf, *fp;
  25.  
  26.     if (wildexp(&argc,&argv) == ERROR)
  27.         exit(puts("WILDEXP overflow!"));
  28.     dioinit(&argc, argv);
  29.     if (argc < 2) {
  30.         error("Usage: cat0 file1 file2 ... >outfile");
  31.         exit();
  32.         }
  33.     fp = &inbuf;
  34.     if (argc == 1)
  35.         filecopy(STDIN);
  36.     else
  37.         while (--argc > 0)
  38.             if (fopen(*++argv, fp) == 0) {
  39.                 fprintf(STDERR, "cat: can't open %s\n", *argv);
  40.                 exit(1);
  41.                 }
  42.             else {
  43.                 filecopy(fp);
  44.                 fclose(fp);
  45.                 }
  46.     dioflush();
  47. }
  48.  
  49.  
  50. filecopy(inbuf)
  51. FILE *inbuf;
  52. {
  53.     int c;
  54.  
  55.     while ((c = getc(inbuf)) != EOF && c != CPMEOF) {
  56.         if (c == '\r')
  57.             if ((c = getc(inbuf)) != '\n')
  58.                 putchar('\r');
  59.         putchar(c);
  60.         }
  61. }
  62.